import {Service, action} from "adajs";
import BaomingList from "../../lists/baoming";
import User from './../../../lib/user';

class NewsService extends Service {
    defaultData() {
        return {
            isLoad: false,
            newsInfo: {
                crtIp: "120.244.109.161",
                crtTime: "2018-12-18 21:41:06",
                crtUser: "admin",
                id: "cf84d7b4-e9ca-4ce5-a07d-06c0acddd3f8",
                jssj: "2019-01-31 00:00:00",
                kcjj: "1",
                kcmc: "12-19",
                kssj: "2018-12-19 00:00:00",
                lsjj: "1",
                rkls: "雷凯·1234",
                sfyxbb: 1,
                skdd: "2",
                skpc: "3"
            },
            id: "",
            list: {
                type: BaomingList,
                url: "/api/lgb/app/lgb/courseapply/queryPage",
                parameter: {
                    kcmc: "",
                    t: new Date()
                }
            }
        };
    }

    onupdate(current, id) {
        if (id) {
            return this.context.request.post(User.isAdmin() ? "/api/admin/lgb/courseinfor/get" : "/api/lgb/app/lgb/courseinfor/get", {id}).then(({data}) => {
                current.id = id;
                current.isLoad = true;
                if (User.isAdmin()) {
                    current.newsInfo = data;
                    current.list.parameter.kcmc = data.kcmc;
                } else {
                    current.newsInfo = data;
                    current.list.parameter.kcmc = data.kcmc;
                }
            });
        }
    }

    @action("refreshTable")
    refreshTable(current) {
        current.list.parameter.t = new Date();
    }
}

export default NewsService;